import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import store from './store'
// element-plus ElMessage图标不展示需要引入样式
import 'element-plus/dist/index.css'
import preHead from './components/preHead.vue'

// 如果您正在使用CDN引入，请删除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { tr } from 'element-plus/es/locales.mjs'




const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 页面顶部说明需要全局添加组件
app.component('preHead',preHead)


// 总体token跳转逻辑
router.beforeEach((to,from) =>{
  const token = localStorage.getItem('pz-token')
  // 非登录页面token不存在
  if(!token && to.path !== '/login'){
    return '/login'
  }else if(token && to.path === '/login' ){
    return '/'
  }else{
    return true
  }
})



// 路由挂载
app.use(router)
// vuex store挂载
app.use(store)
app.mount('#app')
